<?php

namespace App\Controller;

use App\Entity\FileObject;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Vich\UploaderBundle\Handler\DownloadHandler;

/**
 * Class DisplayFilesController 文件查看
 * @package App\Controller
 */
class DisplayFilesController extends AbstractController
{

    /**
     * @var DownloadHandler
     */
    private $downloadHandler;

    public function __construct(DownloadHandler $downloadHandler)
   {
       $this->downloadHandler = $downloadHandler;
   }

    /**
     * @param FileObject $data
     * @return StreamedResponse
     */
    public function __invoke(FileObject $data)
    {
        return $this->downloadHandler->downloadObject($data, 'file', null, null, false);
    }
}
